//
//  VideoListViewController.m
//  RONGAO
//
//  Created by wei wang on 2017/3/14.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "VideoListViewController.h"
#import "LocaViewController.h"
#import "RemoteViewController.h"
#import "EventListViewController.h"

#define VIDEO_LOCAL_SOURCE_TYPE     1
#define VIDEO_REMOTE_SOURCE_TYPE    2


@interface VideoListViewController ()<UITableViewDelegate,UITableViewDataSource>

/** tableview **/
@property(nonatomic,strong) UITableView *tableView;


@end

@implementation VideoListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationStyle];
    [self masLayoutSubview];
    

}

- (void)setNavigationStyle{
    [self setNavigationTitle:@"录像视频" titleColor:[UIColor colorWithRed:210/255.0 green:177/255.0 blue:104/255.0 alpha:1]];
    [self setLeftButtonImage:[UIImage imageNamed:@"icon_back_nor"]];
}
- (BOOL)prefersStatusBarHidden {
    return NO;
}


#pragma mark - tableview DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
    
}
#pragma mark - tableview Delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 56;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
    
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.textLabel.textColor = [UIColor colorWithHexString:@"#56504f"];
        [cell.textLabel setFont:[UIFont systemFontOfSize:15.f]];    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0) {
        
        cell.textLabel.text = @"本地视频";
        
        
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"设备视频";
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        LocaViewController *vc = [LocaViewController new];
        vc.directoryPath = self.directoryPath;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];

    }else if (indexPath.row == 1){
        
        EventListViewController *vc = [EventListViewController new];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)masLayoutSubview{
    
    __weak UIView *superView = self.view;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(superView);
        
    }];
    
}


- (NSInteger)dataSourceNum:(NSString *)uid type:(NSInteger)type
{
    NSInteger num = 0;
    
    if(VIDEO_LOCAL_SOURCE_TYPE == type) {
        FMResultSet *rs = [[AppDelegate globalDelegate].database executeQuery:@"SELECT * FROM record WHERE dev_uid=?", uid];
        while([rs next]) {
            ++num;
        }
        [rs close];
    }
    //NSLog(@"uid:%@   num:%d", uid, num);
    return num;
}

- (NSString *)directoryPath {
    
    if (!_directoryPath) {
        
        NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        _directoryPath = [dirs objectAtIndex:0];
    }
    return _directoryPath;
}

- (UITableView *)tableView{
    
    if (!_tableView) {
        
        __weak UIView *superView = self.view;
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        [superView addSubview:_tableView];
        //        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;//隐藏tableView的分割线
        //        _tableView.scrollEnabled = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
    }
    
    return _tableView;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
